webpackJsonp([7],{

/***/ 0:
/***/ (function(module, exports, __webpack_require__) {

	var APP = __webpack_require__(1);
	var VALIDATE = __webpack_require__(17);
	var UTIL = __webpack_require__(18);
	var USER = __webpack_require__(9);
	var Config = __webpack_require__(4);

	var page = {
	    subject: null,
		activeIndex:0,
		footerHeight:null,
		xyType:'user',
		zknightCode:null,
		checkTime:null,//倒计时
		device_id:'ces',//设备id
		codeId:'',//二维码id
		language:'cn',
	    ready : function() {
	        var that = this;
			var language = navigator.language
			try{
				let _txt = language.split('-')[0];
				if(_txt == 'zh'){
					that.language = 'cn'
				}else{
					that.language = 'en'
				}
			}catch(e){
				//TODO handle the exception
			}
			var winHeight = api.winHeight;
			if(winHeight < 1070){
				$('.login-con').addClass('active');
			}else{
				$('.login-con').removeClass('active');
			}
			// 头部处理
			var headerHeight = $('#header').height();
			$('body').css('padding-top', headerHeight);
			
			// var F_Account = API.getStorage('F_Account');
			var F_Account = api.getPrefs({
			   sync: true,
			   key: 'F_Account'
			});
			// var F_Password = API.getStorage('F_Password');
			var F_Password = api.getPrefs({
			   sync: true,
			   key: 'F_Password'
			});
			
			if(F_Account) {
				$("[name='mobile']").val(F_Account);
			}
			if(F_Password) {
				$("[name='mobile-psd']").val(F_Password);
			}
			//传入展示图形验证码位置的ID,若只传ID，则其他参数使用默认值
			that.zknightCode = new zknightH5imagecaptcha("captcha");
			
			
			// 设置语言
			let lang =  api.getGlobalData({key: 'lang'});
			if(!lang){
				api.setGlobalData({
				    key: 'lang',
				    value: that.language
				});
			}else{
				that.language = lang;
			}
			if(that.language == 'cn'){
				$('.chinese').addClass('active').siblings().removeClass('active');
			}else{
				$('.english').addClass('active').siblings().removeClass('active');
			}
			i18n("[i18n]", {
				lang: that.language,// 变更语言
				filePath: "i18n/",
				get: true
			});
			
			i18n("[i18n]", {
				defaultLang: that.language, // 设置默认语言，
				filePath: "i18n/",
				filePrefix: "i18n_",
				fileSuffix: "",
				forever:true,// 默认为 true  保存当前语言，设置为 false 后，每次刷新都为cn 
				get: true,
				only: ['value', 'html', 'placeholder', 'title'], // 全局设置i18n-only，默认值：['value', 'html', 'placeholder', 'title']
				callback: function() {
					console.log("i18n is ready.");
				}
			});
			
			
	    },
	    on : function() {
			var that = this;
			// 赋值账号密码
			API.listenEvt('LOGOUT', function() {
				var F_Account = api.getPrefs({
			   sync: true,
			   key: 'F_Account'
			});
			var F_Password = api.getPrefs({
			   sync: true,
			   key: 'F_Password'
			});
				
				if(F_Account) {
					$("[name='mobile']").val(F_Account);
				}
				
				if(F_Password) {
					$("[name='mobile-psd']").val(F_Password);
				}
			});
			//首页点击返回
			API.listenEvt('keyback', function() {
				let msg = i18n.get("exit.app") || '再点一次退出应用';
				api.toast({
			        msg : msg,
			        duration : 2000,
			        location : 'bottom'
			    });
			    API.listenEvt('keyback', function() {
			    	api.closeWidget({
			            silent : true
			        });
			    });
			});
			var events = [
				//打开页面
				['.openPage', function() {
					var _url = $(this).data('url');
					let toast = i18n.get("system.under.development") || '系统开发中...';
					if (_url) {
						APP.w.openWin(_url);
					} else {
						API.errorToast(toast);
					}
				}],
				
				// 切换为扫码登录
				['.pwd-con .codelogin', function() {
					that.createLogin();
					that.checkTime = setInterval(function(){
						that.checkLogin();
					},1000)
					$('.pwd-con').hide();
					$('.code-con').show();
				}],
				// 切换为密码登录
				['.code-con .return', function() {
					clearInterval(that.checkTime);
					$('.code-con').hide();
					$('.pwd-con').show();
				}],
				// 切换为英文
				['.english', function() {
					i18n("[i18n]", {
						lang: "en",// 变更语言
						filePath: "i18n/",
						get: true
					});
					api.setGlobalData({
					    key: 'lang',
					    value: 'en'
					});
					$(this).addClass('active').siblings().removeClass('active');
					console.log("中文===============")
					console.log(i18n.get("footer.about"));
				}],
				// 切换为中文
				['.chinese', function() {
					i18n("[i18n]", {
						lang: "cn",// 变更语言
						filePath: "i18n/",
						get: true
					});
					api.setGlobalData({
					    key: 'lang',
					    value: 'cn'
					});
					$(this).addClass('active').siblings().removeClass('active');
					console.log("中文===============")
					console.log(i18n.get("footer.about"));
				}],
			];
			APP.e.more(events);
			//提交表单
			$(document).on('click','#login-sub',function(){
				var _Phone = $(".phone").val();
				var _Password = $(".password").val();
				var _code = $(".form-lis-code .code").val();
				let toast1 = i18n.get("mobile.empty") || '手机号不能为空！';
				let toast2 = i18n.get("mobile.error") || '请输入正确的手机号！';
				let toast3 = i18n.get("password.empty") || '密码不能为空！';
				if(!_Phone){
					API.errorToast(toast1);
					return;
				}
				if(!checkPhone(_Phone)){
					API.errorToast(toast2);
					return false;
				}
				if(!_Password){
					API.errorToast(toast3);
					return false;
				}
				if(!_code){
					// API.errorToast('验证码不能为空！');
					// return false;
				}
				
				//文本框输入的验证码
				var zknightInputCode = document.getElementById("code").value;
				//传入输入的验证码，返回验证结果
				var result = that.zknightCode.validate(zknightInputCode);
				var postData = {
					account: _Phone,
					password: _Password,
				}
				that.loginUp(postData);
				
				// if(!result){
				// 	var postData = {
				// 		account: _Phone,
				// 		password: _Password,
				// 	}
				// 	that.loginUp(postData);
				// }else{
				// 	API.errorToast('验证码错误！');
				// }
			})
			//检查手机
			var checkPhone = function(val) {
			  	var pattern = /^1[3456789]\d{9}$/;
			  	return pattern.test(val);
			};
			//批量事件end
			
			//监听手机号并验证
			$('#mobile').bind('input propertychange', function() {});
			window.onresize = () => {
				var winHeight = api.winHeight;
			  if(winHeight < 1070){
			  	$('.login-con').addClass('active');
			  }else{
				$('.login-con').removeClass('active');
			  }
			}
	    },
	    methods : {
			
			//检测扫码登录 device/check_login
			checkLogin: function(){
				var that = this;
				var postData = {
					id: that.codeId,
				}
				APP.r.post({
					api: 'device/check_login',
					params: postData,
					success: function(res) {
						// 1 未扫码 2已扫码未确定 3已扫码确定登录
						if(res.data.status == 3){
							
							clearInterval(that.checkTime)
							USER.setUserToken(res.data.token);//缓存token
							that.getUserInfo()
						}
					}
				});
				
			},
			//获取用户信息
			getUserInfo: function(){
				var that = this;
				APP.r.post({
					api: 'user/get_user_info',
					params: {},
					success: function(res) {
						USER.setUserinfo(res.data.userinfo);
						USER.setUserToken(res.data.userinfo.token);//缓存token
						let _txt = i18n.get("login.succeeded") || '登录成功';
						API.successToast(_txt, function() {
							$('.code-con').hide();
							$('.pwd-con').show();
							API.sendEvt('LOGIN_SUCCESS');
						    APP.w.openWin("index_main");
						});
					}
				});
			},
			// 获取二维码
			createLogin: function(){
				var that = this;
				var _params = {
					device_id: that.device_id,
				}
				APP.r.post({
					api: 'device/create_login',
					params: _params,
					success: function(ret) {
						var _img = Config.imgHost + ret.data.url;
						that.codeId =  ret.data.id;
						$('.login-code img').attr('src',_img);
					}
				});
			},
			// 密码登录
			loginUp: function(postData){
				var that = this;
				APP.r.post({
					api: 'user/login',
					params: postData,
					success: function(res) {
						// API.setStorage(APP.Key.user_token, res.data.token);
						USER.setUserinfo(res.data.userinfo);
						USER.setUserToken(res.data.userinfo.token);//缓存token
						API.sendEvt('LOGIN_SUCCESS');
						let _txt = i18n.get("login.succeeded") || '登录成功';
						API.successToast(_txt, function() {
						    APP.w.openWin("index_main");
							// $("[name='mobile']").val('');
							// $("[name='mobile-psd']").val('');
							// $("[name='code']").val('');
						});
					}
				});
			},
	    }
	}
	API.run(page);



/***/ }),

/***/ 17:
/***/ (function(module, exports) {

	module.exports = {
		//检查手机
		checkPhone : function(val) {
			var pattern = /^1[3456789]\d{9}$/;
			return pattern.test(val);
		},
		//检查身份证
		checkIdCardNo : function(val) {
			var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
			return pattern.test(val);
		},
		//检查密码
		// checkPassword : function(val) {
		// 	var len = val.length;
		// 	if (len > 20 || len < 6) {
		// 		return false;
		// 	}
		// 	return true;
		// },
		//检查密码
		checkPassword : function(val) {
			var pattern = /^\w{6,16}$/;
			return pattern.test(val);
		},
		//邀请码
		checkCode : function(val) {
			var len = val.length;
			if (len != 6) {
				return false;
			}
			return true;
		},
		checkAreaId : function(val) {
			var len = val.length;
			if (len != 6) {
				return false;
			}
			return true;
		},
		// 检查姓名
		checkName : function(val) {
			var pattern = /^[0-9A-Za-z_|\u4e00-\u9fa5]{1,}$/;
			return pattern.test(val);
		},
	}


/***/ }),

/***/ 18:
/***/ (function(module, exports) {

	module.exports = {
		countdown : 60,
		//发送验证码倒计时
		settime : function(obj) {
			var that = this;
			if (that.countdown == 0) {
				obj.setAttribute("rel", 'send');
				obj.innerHTML = "重新发送";
				obj.className += ' codeBtn';
				that.countdown = 60;
				return;
			} else {
				obj.removeAttribute("rel");
				obj.innerHTML = "重新发送(" + that.countdown + 's' + ")";
				that.countdown--;
			}
			setTimeout(function() {
				that.settime(obj)
			}, 1000)
		},
		//秒杀倒计时
		countTime : function(_date, callback) {
			var that = this;
			//获取当前时间
			var date = new Date();
			var now = date.getTime();
			//设置截止时间
			_date = _date.replace(/-/g, '/'); 
			var endDate = new Date(_date);
			var end = endDate.getTime();
			//时间差
			var leftTime = end - now;
			//定义变量 d,h,m,s保存倒计时的时间
			var d, h, m, s;
			if (leftTime >= 0) {
				d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
				h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
				m = Math.floor(leftTime / 1000 / 60 % 60);
				s = Math.floor(leftTime / 1000 % 60);
				
				h = (h+"").length == 1 ? '0'+h : h;
				m = (m+"").length == 1 ? '0'+m : m;
				s = (s+"").length == 1 ? '0'+s : s;
				//将倒计时赋值到div中
				//obj.find('[rel="_d"]').html(d);
				//obj.find('[rel="_h"]').html(h);
				//obj.find('[rel="_m"]').html(m);
				//obj.find('[rel="_s"]').html(s);
				
				if(d>0) {
					document.getElementById("t_day").innerHTML = d+'日';
				}
				document.getElementById("t_hour").innerHTML = h;
				document.getElementById("t_minute").innerHTML = m;
				document.getElementById("t_second").innerHTML = s;

				//递归每秒调用countTime方法，显示动态时间效果
				setTimeout(function() {
					that.countTime(_date, callback);
				}, 1000);
			} else {
				$.isFunction(callback) && callback();
			}
		},
		countTimeMuti : function(_obj, callback) {
			var that = this;
			//获取当前时间
			var date = new Date();
			var now = date.getTime();
			//设置截止时间
			var _date = _obj.data('startdate');
			_date = _date.replace(/-/g, '/'); 
			var endDate = new Date(_date);
			var end = endDate.getTime();
			//时间差
			var leftTime = end - now;
			//定义变量 d,h,m,s保存倒计时的时间
			var d, h, m, s;
			if (leftTime >= 0) {
				d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
				h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
				m = Math.floor(leftTime / 1000 / 60 % 60);
				s = Math.floor(leftTime / 1000 % 60);
				
				h = (h+"").length == 1 ? '0'+h : h;
				m = (m+"").length == 1 ? '0'+m : m;
				s = (s+"").length == 1 ? '0'+s : s;
				//将倒计时赋值到div中
				
				_obj.find('.t_hour').text(h);
				_obj.find('.t_minute').text(m);
				_obj.find('.t_second').text(s);

				//递归每秒调用countTime方法，显示动态时间效果
				setTimeout(function() {
					that.countTimeMuti(_obj, callback);
				}, 1000);
			} else {
				$.isFunction(callback) && callback();
			}
		},
		//展示时间类型
		showMusicTimeText: function(duration) {
			if(duration<10) return '00:0'+duration.toFixed(0);
			var _m = Math.floor(duration/60).toFixed(0);
			if(_m < 10) _m = '0'+_m;
			var _s = Math.floor(duration%60).toFixed(0);
			if(_s < 10) _s = '0'+_m;
			return _m+':'+_s;
		}
	}

/***/ })

});